<?php


if (!defined('TINY_MCE')) {
	define('TINY_MCE', APP . 'plugins' . DS . 'schema' . DS . 'webroot' . DS . 'tiny_mce' . DS);
}

if (!defined('TINY_MCE_URL')) {
	define('TINY_MCE_URL', '/schema/tiny_mce/');
}

$config_gzip = array(
	'languages' => 'en',
	'themes' => 'simple,advanced',
	'plugins' => 'pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave',
	'disk_cache' => TRUE,
	'debug' => FALSE
);

$config = array(
	'mode' => 'exact',
	'elements' => $options['id'],
	'language' => 'en',
	'theme' => 'advanced',
	'theme_advanced_resize_horizontal' => FALSE,
	'convert_urls' => FALSE
);

if (App::import('Core', 'L10n')) {
	$l10n = new L10n();
	$l10n->get(Configure::read('Config.language'));
	if (!in_array($l10n->locale, (array)Configure::read('Config.languages')) && defined('DEFAULT_LANGUAGE')) {
		$l10n->get(DEFAULT_LANGUAGE);
	}
	if (strlen($l10n->lang) == 2) {
		$language = strtolower($l10n->lang);
	} else {
		$language = $l10n->map($l10n->locale);
	}
	if (($language != 'en') && is_file(TINY_MCE . 'langs' . DS . $language . '.js')) {
		$config_gzip['languages'] .= ',' . $language;
		$config['language'] = $language;
	}
}

if (is_file(CSS . 'wysiwyg.css')) {
	$config['content_css'] = $this->Html->url('/css/wysiwyg.css');
}

$config_gzip = Set::merge($config_gzip, (array)Configure::read('TinyMCE_GZ'));

$config = Set::merge($config, (array)Configure::read('TinyMCE'));

$themes = array(
	'word' => array(
		'theme' => 'advanced',
		'plugins' => 'pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave',
		'theme_advanced_buttons1' => 'save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect',
		'theme_advanced_buttons2' => 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor',
		'theme_advanced_buttons3' => 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen',
		'theme_advanced_buttons4' => 'insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft',
		'theme_advanced_toolbar_location' => 'top',
		'theme_advanced_toolbar_align' => 'left',
		'theme_advanced_statusbar_location' => 'bottom',
		'theme_advanced_resizing' => TRUE
	),
	'full' => array(
		'theme' => 'advanced',
		'plugins' => 'pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave',
		'theme_advanced_buttons1' => 'save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect',
		'theme_advanced_buttons2' => 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor',
		'theme_advanced_buttons3' => 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen',
		'theme_advanced_buttons4' => 'insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft',
		'theme_advanced_toolbar_location' => 'top',
		'theme_advanced_toolbar_align' => 'left',
		'theme_advanced_statusbar_location' => 'bottom',
		'theme_advanced_resizing' => TRUE
	),
	'cake' => array(
		'theme' => 'advanced',
		'plugins' => 'pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist',
		'theme_advanced_buttons1' => 'save,newdocument,pagebreak,|,print,preview,|,cut,copy,paste,pastetext,pasteword,cleanup,|,search,replace,|,undo,redo,|,charmap,template,styleselect,attribs,code,|,visualchars,nonbreaking,|,fullscreen',
		'theme_advanced_buttons2' => 'removeformat,styleprops,formatselect,fontselect,fontsizeselect,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,forecolor,backcolor',
		'theme_advanced_buttons3' => 'link,unlink,anchor,image,media,|,visualaid,tablecontrols,|,sub,sup,|,blockquote,advhr,|,insertdate,inserttime',
		'theme_advanced_toolbar_location' => 'top',
		'theme_advanced_toolbar_align' => 'left',
		'theme_advanced_statusbar_location' => 'bottom',
		'theme_advanced_resizing' => TRUE
	)
);

if (isset($options['readonly']) && (bool)$options['readonly']) {
	$config['theme'] == 'simple';
	$config['readonly'] == TRUE;
} else {
	if (isset($options['theme'])) {
		$config['theme'] = $options['theme'];
	}
	if (isset($themes[$config['theme']])) {
		$config = Set::merge($config, $themes[$config['theme']]);
	}
	if (isset($options['config'])) {
		$config = Set::merge($config, $options['config']);
	}
}

if (is_file(TINY_MCE . 'tiny_mce_gzip.js')) {
	$this->Html->script(TINY_MCE_URL . 'tiny_mce_gzip.js', array('inline' => FALSE));
	$this->Html->scriptBlock('tinyMCE_GZ.init(' . $this->Js->object($config_gzip) . ');', array('inline' => FALSE));
} else {
	$this->Html->script(TINY_MCE_URL . 'tiny_mce.js', array('inline' => FALSE));
}

echo $this->Html->scriptBlock('tinyMCE.init(' . $this->Js->object($config) . ');');


?>